package com.hzdesk.media.koreabatchmatvector.logic.view;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hzdesk.media.koreabatchmatvector.R;
import com.hzdesk.media.koreabatchmatvector.custom.MyRecyclerView;
import com.hzdesk.media.koreabatchmatvector.logic.contract.CloudListContract;
import com.hzdesk.media.koreabatchmatvector.logic.persenter.CloudListPersenter;
import com.hzdesk.media.koreabatchmatvector.utils.MyToastUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import me.zhouzhuo.zzhorizontalprogressbar.ZzHorizontalProgressBar;

/**
 * Created by Administrator on 2018/7/9.
 * 杭州席媒科技有限公司  Developers  刘传华  10
 * 佛祖镇楼 bug辟易
 * <p>
 * TODO: 2018/7/10                                                                               云端管理
 */

public class CloudListActivity extends BaseActivity  implements CloudListContract.ICloudListView {
    @BindView(R.id.activity_cloud_list_iv_back)
    ImageView activityCloudListIvBack;
    @BindView(R.id.activity_cloud_list_iv_intent_to_local)
    ImageView activityCloudListIvIntentToLocal;
    @BindView(R.id.activity_cloud_list_iv_delect_all)
    ImageView activityCloudListIvDelectAll;
    @BindView(R.id.activity_cloud_list_iv_sort)
    ImageView activityCloudListIvSort;
    @BindView(R.id.activity_cloud_list_progress)
    ZzHorizontalProgressBar activityCloudListProgress;
    @BindView(R.id.activity_cloud_list_tv_storage)
    TextView activityCloudListTvStorage;
    @BindView(R.id.activity_cloud_list_listview)
    MyRecyclerView activityCloudListListview;
    @BindView(R.id.activity_cloud_list_ll_bg)
    LinearLayout activityCloudListLlBg;
    private CloudListPersenter mCloudListPersenter = new CloudListPersenter(this);
    private Handler mhandler;
    private RelativeLayout emperty_view;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cloud_list);
        ButterKnife.bind(this);

    }

    @OnClick({R.id.activity_cloud_list_iv_back, R.id.activity_cloud_list_iv_intent_to_local, R.id.activity_cloud_list_iv_delect_all,
            R.id.activity_cloud_list_iv_sort, R.id.activity_cloud_list_progress, R.id.activity_cloud_list_tv_storage})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.activity_cloud_list_iv_back:
                mCloudListPersenter.oncklicdeBack();
                break;
            case R.id.activity_cloud_list_iv_intent_to_local:
                mCloudListPersenter.onCklicedToLocalVido();
                break;
            case R.id.activity_cloud_list_iv_delect_all:
                mCloudListPersenter.delectAllFile();
                break;
            case R.id.activity_cloud_list_iv_sort:
                mCloudListPersenter.sortingList();
                break;
            case R.id.activity_cloud_list_progress:
                break;
            case R.id.activity_cloud_list_tv_storage:
                break;
        }
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        // todo 重新刷新
      //  mCloudListPersenter.updateInitDate();
    }

    @Override
    protected void onStart() {
        super.onStart();
        final SharedPreferences mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        int selector = mSharedPreferences.getInt("item_skin", 0); //todo 名称
        emperty_view = findViewById(R.id.activity_cloud_list_emperty_view);
        mhandler = new Handler();
        mCloudListPersenter.initRecyclerview(this,activityCloudListListview,mhandler);
        mCloudListPersenter.initSpace(activityCloudListProgress,activityCloudListTvStorage);
        activityCloudListListview.setEmptyView(emperty_view);
        activityCloudListLlBg.setBackgroundResource(updateBg[selector]);
    }

    @Override
    protected void onStop() {
        super.onStop();
        finish();
    }

    @Override
    public void toFinshPager() {
        finish();
    }

    @Override
    public void toLocalVido() {
        startActivity(new Intent(this,VideoListActivity.class));
    }

    @Override
    public void showToast(String message) {
        MyToastUtils.ShortToaseShow(this,message);
    }
}
